<template>
  <van-pull-refresh class="dynamic" v-model="loading" @refresh="onRefresh">
    <van-list
      v-model:loading="loadingMore"
      :finished="finished"
      finished-text="没有更多了~"
      @load="onLoad"
    >
      <div class="list">
        <div class="list_item" v-for="i in dataList" @click="toInfo(i)">
          <div class="title">
            {{ i.title }}
          </div>
          <div class="imgs">
            <van-image
              fit="cover"
              v-for="itg in i.homepageImage?.split(',')"
              :src="host + itg"
            />
          </div>
          <div class="time">2019-09-08</div>
        </div>
      </div>
    </van-list>
  </van-pull-refresh>
</template>

<script setup>
import { ref } from "vue";
import { queryNewsFeedRichTextList } from "@/api/index";
import { useRouter } from "vue-router";
let host = import.meta.env.VITE_APP_BASE_API;
let loading = ref(false);
let router = useRouter();
function onRefresh() {
  loading.value = true;
  loadingMore.value = true;
  finished.value = false;
  dataList.value = [];
  page.value.pageNum = 1;
  getList();
}
// 获取首页数据
let page = ref({
  pageNum: 1,
  pageSize: 10,
});
let dataList = ref([]);
function getList() {
  queryNewsFeedRichTextList(page.value).then((res) => {
    loading.value = false;
    loadingMore.value = false;
    dataList.value.push(...res.rows);
    if (res.rows.length < page.value.pageSize) {
      finished.value = true;
    }
  });
}
// 加载更多
let loadingMore = ref(true);
let finished = ref(false);
function onLoad() {
  page.value.pageNum += 1;
  getList();
}
getList();

function toInfo(row) {
  router.push("/txtInfo/" + row.id);
}
</script>

<style scoped lang="scss">
.dynamic {
  padding-bottom: 50px;
  height: calc(100vh - 50px);
  overflow: auto;
}
.list_item {
  color: #666;
  font-size: 15px;
  padding: 10px;
  border-bottom: 1px solid #eee;
  padding: 10px;
  .title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 10px;
    color: #333;

    // font-weight: bold;
  }

  .imgs {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 10px;
    .van-image {
      width: 110px;
      height: 110px;
      border-radius: 4px;
      overflow: hidden;
      margin-right: 10px;
      &:last-child {
        margin-right: 0;
      }
    }
  }
}
</style>
